# 设计模式
# from abc import ABCMeta, abstractmethod
# # 定义抽象接口
# class Payment(met=ABCMeta):
#     @abstractmethod
#     def pay(self, money):
#         pass

# # 单例模式
# class singlee:
#     def __new__(cls, *args, **kwargs):
#         if not hasattr(cls, "_instance"):
#             cls._instance = super(singlee, cls).__new__(cls)
#         return cls._instance
#
#
# class Myclass(singlee):
#     def __init__(self, a):
#         self.a = a
#
#
# a = Myclass(10)
# # 被b调用覆盖前
# print(a, id(a))
# print(a.a)
# b = Myclass(20)
# # 被b调用覆盖前
# print(a, id(a))
# print(a.a)
# print(b, id(b))
# print(b.a)


# # 类适配器模式——少数对象不一致
# class NewPay(转换为对象, 装换的对象):
#     def 转换为对象de属性名称(self, 参数):
#         self.装换的对象de属性名称(参数)
# 对象适配器
# class NewPay(转换为对象):
#     def __init__(self, 转换为对象):
#         self.转换为对象 = 转换为对象
#     # 对对象进行封装再通过类方法调用
#     def 转换为对象de属性名称(self, 参数):
#         self.装换的对象de属性名称(参数)
#
# p = NewPay(装换的类对象)
# # 调用方法进行转换
# P.转换为对象de属性名称(参数)

from abc import ABCMeta, abstractmethod

class Hang(metaclass=ABCMeta):
    # 通过定义成属性，将Lie类与Hang类组合
    def __init__(self, lie):
        self.lie = lie
    @abstractmethod
    def hanghao(self):
        pass


class Lie(metaclass=ABCMeta):
    @abstractmethod
    def liehao(self, hang):
        pass

class hang3(Hang):
    v = "第三行"
    def hanghao(self):
        self.lie.liehao(self)

class hang4(Hang):
    v = '第四行'
    def hanghao(self):
        self.lie.liehao(self)

class lie2(Lie):
    def liehao(self, hang):
        print("%s这是第二列" % hang.v)

class lie3(Lie):
    def liehao(self, hang):
        print("%s这是第三列" % hang.v)


hangss = hang3(lie2())
hangss.hanghao()
